<template>
    <el-dialog v-model="dialogVisible" :title="title" :width="width" 
    :destroy-on-close="destroyOnClose"
    :draggable="true" :close-on-click-modal="false"
    :close-on-press-escape="false">
        <slot></slot>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="submit" :loading="btnLoading">
                    {{ confirmText }}
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref } from 'vue'

const dialogVisible = ref(false)

const open = () => dialogVisible.value = true

const close = () => dialogVisible.value = false

const btnLoading = ref(false)

const showBtnLaoding = () => btnLoading.value = true

const closeBtnLaoding = () => btnLoading.value = false

defineExpose({
    open,
    close,
    showBtnLaoding,
    closeBtnLaoding
})

const props = defineProps({
    title: String,
    width: {
        type: String,
        default: '40%' // 默认值
    },
    destroyOnClose: {
        type: Boolean,
        default: false
    },
    confirmText: {
        type: String,
        default: '提交'
    }
})

const emit = defineEmits(['submit'])
const submit = () => emit('submit')

</script>